package top.shen33.yang.services.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import top.shen33.yang.model.entity.IpProxy;
import top.shen33.yang.mapper.IpProxyMapper;
import top.shen33.yang.services.IpProxyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * ip代理 服务实现类
 * </p>
 *
 * @author oreilly
 * @since 2018-08-28
 */
@Service
public class IpProxyServiceImpl extends ServiceImpl<IpProxyMapper, IpProxy>implements IpProxyService {


    @Override
    public Class clazz() {
        return IpProxy.class;
    }

    @Override
    @Transactional
    public void doAdd(IpProxy itemIpProxy) {

        itemIpProxy.insertOrUpdate();
    }

    @Override
    @Transactional
    public void doUpdate(IpProxy itemIpProxy) {

        itemIpProxy.insertOrUpdate();
    }

    @Override
    @Transactional
    public void doDelete(String[] ids) {

        QueryWrapper<IpProxy> ew = new QueryWrapper<>();
        ew.in("sid", ids);
        new IpProxy().delete(ew);
    }


    @Override
    public List<IpProxy> all(IpProxy itemIpProxy) {

        return this.baseMapper.all(itemIpProxy);
    }


        @Override
    public Page<IpProxy> pageInfo(Page page, IpProxy itemIpProxy) {

        List<IpProxy> dataList = this.baseMapper.pageInfo(page, itemIpProxy);
        if(page ==null ){
            page = new Page(0,10000);
        }
        page.setRecords(dataList);
        return page;
    }


    @Override
    @Transactional
    public void doImport(List<IpProxy> dataList) {

        //数据验证

        //保存
        this.saveOrUpdateBatch(dataList);
    }

    @Override
    public IpProxy getOne(String id) {
        return getById(id);
    }


}
